// @ts-ignore
/* eslint-disable */
import { request, requestAuth } from '@/utils/request';

/** 发送短信验证码 */
export async function sendPhoneValidCode(data: { phone: string }) {
  return request({
    method: 'POST',
    url: '/api/sendSms',
    data,
  });
}

/** 获取文件临时路径 */
export async function fetchFileUrlById(data: { id: string }) {
  return new Promise((resolve, reject) => {
    requestAuth({
      method: 'POST',
      url: '/api/system/file/download',
      responseType: 'blob',
      data,
    })
      .then(({ blob }) => {
        resolve(window[window.webkitURL ? 'webkitURL' : 'URL'].createObjectURL(new Blob([blob])));
      })
      .catch((err) => {
        reject(err);
      });
  });
}

/** 省市区 */
export async function fetchDistrictList(data: { parentDistrictId: string }) {
  return request({
    method: 'POST',
    url: '/api/system/district/subCities',
    data,
  });
}
